<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="foo"></div>
<template id="bar">
    <script>console.log('模板里面的script')</script>
</template>
<script>
    /*
        模板脚本,用于延迟执行script   
     */
    const fooElement = document.querySelector('#foo');
    const barTemplate = document.querySelector('#bar');
    const barFragment = barTemplate.content;
    console.log('About to add template');
    fooElement.appendChild(barFragment);
    console.log('Added template');
    /*
        输出为:
        About to add template
        模板里面的script
        Added template
     */
</script>
</body>
</html>